---
layout: "default"
title: "DictionaryIndex"
description: "Swift documentation for 'DictionaryIndex': Used to access the key-value pairs in an instance of
Dictionary&lt;Key, Value&gt;."
keywords: "DictionaryIndex,struct,swift,documentation,advancedBy,advancedBy,distanceTo,successor"
root: "/v2.0"
---

<div class="intro-declaration"><code class="language-swift">struct DictionaryIndex&lt;Key : Hashable, Value&gt;</code></div>

<div class="discussion comment">
    <p>Used to access the key-value pairs in an instance of
<code>Dictionary&lt;Key, Value&gt;</code>.</p>

<p>Dictionary has two subscripting interfaces:</p>

<ol><li><p>Subscripting with a key, yielding an optional value:</p><p>   v = d[k]!</p></li><li><p>Subscripting with an index, yielding a key-value pair:</p><p>   (k,v) = d[i]</p></li></ol>
</div>

<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<code class="inherits">Comparable, Equatable, ForwardIndexType, _Incrementable</code>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>



<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>







<h3>Instance Methods</h3>
<div class="declaration inherited" id="func-advancedby_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-advancedby_">func advancedBy(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-advancedby_"><div class="p">
    <p>Return the result of advancing <code>self</code> by <code>n</code> positions.</p>

<p><strong>Returns:</strong>
  - If <code>n &gt; 0</code>, the result of applying <code>successor</code> to <code>self</code> <code>n</code> times.
  - If <code>n &lt; 0</code>, the result of applying <code>predecessor</code> to <code>self</code> <code>-n</code> times.
  - Otherwise, <code>self</code>.</p>

<p><strong>Requires:</strong> <code>n &gt;= 0</code> if only conforming to <code>ForwardIndexType</code>
<strong>Complexity:</strong>
  - O(1) if conforming to <code>RandomAccessIndexType</code>
  - O(<code>abs(n)</code>) otherwise</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func advancedBy(n: DictionaryIndex&lt;Key, Value&gt;.Distance) -&gt; DictionaryIndex&lt;Key, Value&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/ForwardIndexType/"><code>ForwardIndexType</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-advancedby_limit_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-advancedby_limit_">func advancedBy(<wbr>_:<wbr>limit:)</a>
        
<div class="comment collapse" id="comment-func-advancedby_limit_"><div class="p">
    <p>Return the result of advancing <code>self</code> by <code>n</code> positions, or until it
equals <code>limit</code>.</p>

<p><strong>Returns:</strong>
  - If <code>n &gt; 0</code>, the result of applying <code>successor</code> to <code>self</code> <code>n</code> times
    but not past <code>limit</code>.
  - If <code>n &lt; 0</code>, the result of applying <code>predecessor</code> to <code>self</code> <code>-n</code> times
    but not past <code>limit</code>.
  - Otherwise, <code>self</code>.</p>

<p><strong>Requires:</strong> <code>n &gt;= 0</code> if only conforming to <code>ForwardIndexType</code>.</p>

<p><strong>Complexity:</strong>
  - O(1) if conforming to <code>RandomAccessIndexType</code>
  - O(<code>abs(n)</code>) otherwise</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func advancedBy(n: DictionaryIndex&lt;Key, Value&gt;.Distance, limit: DictionaryIndex&lt;Key, Value&gt;) -&gt; DictionaryIndex&lt;Key, Value&gt;</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/ForwardIndexType/"><code>ForwardIndexType</code></a>    
</div></div>
</div>
<div class="declaration inherited" id="func-distanceto_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-distanceto_">func distanceTo(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-distanceto_"><div class="p">
    <p>Measure the distance between <code>self</code> and <code>end</code>.</p>

<p><strong>Requires:</strong>
  - <code>start</code> and <code>end</code> are part of the same sequence when conforming to
    <code>RandomAccessSequenceType</code>.
  - <code>end</code> is reachable from <code>self</code> by incrementation otherwise.</p>

<p><strong>Complexity:</strong>
  - O(1) if conforming to <code>RandomAccessIndexType</code>
  - O(<code>n</code>) otherwise, where <code>n</code> is the function&#39;s result.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func distanceTo(end: DictionaryIndex&lt;Key, Value&gt;) -&gt; DictionaryIndex&lt;Key, Value&gt;.Distance</code>
    
        <h4>Declared In</h4>
        <a href="../../protocol/ForwardIndexType/"><code>ForwardIndexType</code></a>    
</div></div>
</div>
<div class="declaration" id="func-successor">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-successor">func successor()</a>
        
<div class="comment collapse" id="comment-func-successor"><div class="p">
    <p>Returns the next consecutive value after <code>self</code>.</p>

<p><strong>Requires:</strong> The next value is representable.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func successor() -&gt; DictionaryIndex&lt;Key, Value&gt;</code>
    
    
</div></div>
</div>


